package com.kobe.manager.purposeManager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.kobe.common.annotation.Log;
import com.kobe.common.core.controller.BaseController;
import com.kobe.common.core.domain.AjaxResult;
import com.kobe.common.enums.BusinessType;
import com.kobe.manager.purposeManager.domain.Purpose;
import com.kobe.manager.purposeManager.service.IPurposeService;
import com.kobe.common.utils.poi.ExcelUtil;
import com.kobe.common.core.page.TableDataInfo;

/**
 * 采购意向Controller
 *
 * @author panchengjiang
 * @date 2025-10-23
 */
@RestController
@RequestMapping("/purposeManager/purpose")
public class PurposeController extends BaseController
{
    @Autowired
    private IPurposeService purposeService;

    /**
     * 查询采购意向列表
     */
    @PreAuthorize("@ss.hasPermi('purposeManager:purpose:list')") // 权限控制
    @GetMapping("/list") // 请求地址
    public TableDataInfo list(Purpose purpose)
    {
        startPage();
        List<Purpose> list = purposeService.selectPurposeList(purpose);
        return getDataTable(list);
    }

    /**
     * 导出采购意向列表
     */
    @PreAuthorize("@ss.hasPermi('purposeManager:purpose:export')")
    @Log(title = "采购意向", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Purpose purpose)
    {
        List<Purpose> list = purposeService.selectPurposeList(purpose);
        ExcelUtil<Purpose> util = new ExcelUtil<Purpose>(Purpose.class);
        util.exportExcel(response, list, "采购意向数据");
    }

    /**
     * 获取采购意向详细信息
     */
    @PreAuthorize("@ss.hasPermi('purposeManager:purpose:query')")
    @GetMapping(value = "/{purposeId}")
    public AjaxResult getInfo(@PathVariable("purposeId") Long purposeId)
    {
        return success(purposeService.selectPurposeByPurposeId(purposeId));
    }

    /**
     * 新增采购意向
     */
    @PreAuthorize("@ss.hasPermi('purposeManager:purpose:add')")
    @Log(title = "采购意向", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Purpose purpose)
    {
        return toAjax(purposeService.insertPurpose(purpose));
    }

    /**
     * 修改采购意向
     */
    @PreAuthorize("@ss.hasPermi('purposeManager:purpose:edit')")
    @Log(title = "采购意向", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Purpose purpose)
    {
        return toAjax(purposeService.updatePurpose(purpose));
    }

    /**
     * 删除采购意向
     */
    @PreAuthorize("@ss.hasPermi('purposeManager:purpose:remove')")
    @Log(title = "采购意向", businessType = BusinessType.DELETE)
    @DeleteMapping("/{purposeIds}")
    public AjaxResult remove(@PathVariable Long[] purposeIds)
    {
        return toAjax(purposeService.deletePurposeByPurposeIds(purposeIds));
    }
}
